﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.IO;

namespace OnlineShopTest
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        private TextBox shopName = new TextBox();
        Shop theShop;
        public MainWindow()
        {
            InitializeComponent();
            InitializeStartPage();
        }

        private void InitializeStartPage()
        {
            mainGrid.Children.Clear();
            mainGrid.RowDefinitions.Clear();
            mainGrid.ColumnDefinitions.Clear();

            for (int rows = 0; rows < 4; rows++)
            {
                mainGrid.RowDefinitions.Add(new RowDefinition());
            }

            Button addUser = new Button() { Content = "Add new user",};
            Button loginUser = new Button() { Content = "Login as user"};
            Button addShop = new Button() { Content = "Add new shop"};
            Button loginShop = new Button() { Content = "Login as shop"};

            Grid.SetRow(addUser, 0);
            Grid.SetRow(loginUser, 1);
            Grid.SetRow(addShop, 2);
            Grid.SetRow(loginShop, 3);

            addUser.Click += OnAddUserClick;
            loginUser.Click += OnLoginUserClick;
            addShop.Click += OnAddShopClick;
            loginShop.Click += OnLoginShopClick;

            mainGrid.Children.Add(addUser);
            mainGrid.Children.Add(loginUser);
            mainGrid.Children.Add(addShop);
            mainGrid.Children.Add(loginShop);

        }

        private void ShowAddShopMenu()
        {
            mainGrid.Children.Clear();
            mainGrid.RowDefinitions.Clear();
            mainGrid.ColumnDefinitions.Clear();

            shopName.Margin = new Thickness(116, 10, 0, 0);
            Button addShop = new Button() { Content = "Add", Margin = new Thickness(10, 50, 0, 0), MaxHeight = 25, MaxWidth = 50};
            addShop.Click += OnSubmitShopClick;

            mainGrid.Children.Add(new TextBlock() { Text = "Name of the shop: ", Margin = new Thickness(10, 10, 0, 0) });
            mainGrid.Children.Add(shopName);
            mainGrid.Children.Add(addShop);

        }


        private void ShowLoginShopMenu()
        {
        }

        private void ShowLoginUserMenu()
        {
        }

        private void ShowAddUserMenu()
        {
        }

        void OnLoginUserClick(object sender, RoutedEventArgs e)
        {
            ShowLoginUserMenu();
        }

        void OnLoginShopClick(object sender, RoutedEventArgs e)
        {
            ShowLoginShopMenu();
        }

        void OnAddShopClick(object sender, RoutedEventArgs e)
        {
            ShowAddShopMenu();
        }
        void OnAddUserClick(object sender, RoutedEventArgs e)
        {
            ShowAddUserMenu();
        }

        private void OnSubmitShopClick(object sender, RoutedEventArgs e)
        {
            theShop = new Shop(this.shopName.Text);
            StreamWriter writer = new StreamWriter("Shops.txt", true);
            using (writer)
            {
                writer.WriteLine(theShop.Name);
            }
            mainGrid.Children.Clear();
            mainGrid.Children.Add(new TextBlock() { Text = "Shop: " + theShop.Name, Margin = new Thickness(10, 10, 0, 0)});
            mainGrid.Children.Add(new TextBlock() { Text = "Name of product: ", Margin = new Thickness(10, 40, 0 ,0)});
            TextBox productName = new TextBox() { Margin = new Thickness(115 , 40, 0, 0 ), MaxWidth = 120, MinWidth = 100, MaxHeight = 23, VerticalAlignment = System.Windows.VerticalAlignment.Top, HorizontalAlignment = System.Windows.HorizontalAlignment.Left};
            mainGrid.Children.Add(productName);
            Button addProduct = new Button() { Content = "Add"};
            //addProduct.Click += OnAddProductClick;
        }

        //void OnAddProductClick(object sender, RoutedEventArgs e)
        //{

        //    StreamWriter productsWriter = new StreamWriter();
        //    throw new NotImplementedException();
        //}

    }
}
